require 'SOD/tools/Definitions'
include Definitions

module SOD
  
  class FootprintInterface
    
    attr_accessor :originalView, :visibilityOfLayers
    
    def initialize
      
      @originalView = Sketchup::Camera.new
      @visibilityOfLayers = []
      
    end
    
    def exists?
      
      exist = false
      
      layers.each { |lay| exist = true if lay.name == "Footprint" }
      
      return exist
    
    end
    
    def getFootprintLayer
      
      for i in 0...layers.length
        if layers.at(i).name == "Footprint"
          return i
        end
      end
      
    end
    
    def viewFootprint
      
      originalEye = view.camera.eye
      originalTarget = view.camera.target
      originalUp = view.camera.up

      @originalView.set originalEye, originalTarget, originalUp
      
      #Aktivieren des Layers Footprint
      #footprintLayerPos = getFootprintLayer if (exists?)
      #return if not footprintLayerPos
      #model.active_layer = layers[footprintLayerPos]
      
      @visibilityOfLayers = []
      for i in 0...layers.length
        @visibilityOfLayers << layers[i].visible?
        #layers[i].visible = false
      end
      
      Plugin.model.discardModel
      Plugin.model.footprint.draw
      
      ##Ausrichten der Kamera
      #eye = [0,0,100]
      #target = [0,0,0]
      #up = [0,1,0]
      #
      #cam = Sketchup::Camera.new eye, target, up
      #view.camera = cam
      #
      #view.zoom_extents
      view.tooltip = "Topview on footprint to modify the whole building"
      
    end
    
    def backToLastView
      
      view.camera = @originalView
      
      for i in 0...layers.length
        layers[i].visible = @visibilityOfLayers[i]
      end
      
    end
    
    
  end
  
end
